<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.deltabravomedia.theoldtoad.server.Crew" %>
<%@ page import="com.deltabravomedia.theoldtoad.server.PMF" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<html>
<head><title>The Old Toad Mobile Application Data Control</title></head>
<body>
<h1>The Old Toad Mobile Application Data Control</h1>

<a href="/update.jsp">Return to Main Page</a>

<h2>Crew</h2>
<table border="1">
<tr><th>Name</th><th>Age</th><th>Hometown</th><th>Education</th><th>Family</th>
<th>Favorite Drink</th><th>Favorite Food</th><th>Favorite Sports</th><th>Passions</th>
<th>Likes</th><th>Dislikes</th><th/><th/></tr>
<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Crew.class.getName() + " order by name";
    List<Crew> items = (List<Crew>) pm.newQuery(query).execute();
    if (items.isEmpty()) {
%>
<%
    } else {
        for (Crew item : items) {
        	String keyString = KeyFactory.keyToString(item.getKey());
        	String fileName = "Crew" + item.getName().trim().replaceAll("\\W", "");
        	
        
%>
<tr><td><%=item.getName()%></td><td><%=item.getAge()%></td>
<td><%=item.getHometown()%></td><td><%=item.getEducation()%></td>
<td><%=item.getFamily()%></td><td><%=item.getFavDrink()%></td>
<td><%=item.getFavFood()%></td><td><%=item.getFavTeam()%></td>
<td><%=item.getPassions()%></td><td><%=item.getLikes()%></td>
<td><%=item.getDislikes()%></td>
<td><form enctype="multipart/form-data" action="/uploadImage?<%=fileName%>" method="post">
<input type="file" name="myfile" /><input type="submit" value="Upload Image"/></form></td>
<td><a href="/deleteCrew?<%=keyString%>">Delete</a></td></tr>
<%
        }
    }
    pm.close();
%>
<tr><form action="/createCrew" method="post">
<td><textarea name="name" rows="2" cols="30"></textarea></td>
<td><textarea name="age" rows="2" cols="30"></textarea></td>
<td><textarea name="hometown" rows="2" cols="30"></textarea></td>
<td><textarea name="education" rows="2" cols="30"></textarea></td>
<td><textarea name="family" rows="2" cols="30"></textarea></td>
<td><textarea name="favDrink" rows="2" cols="30"></textarea></td>
<td><textarea name="favFood" rows="2" cols="30"></textarea></td>
<td><textarea name="favTeam" rows="2" cols="30"></textarea></td>
<td><textarea name="passions" rows="2" cols="30"></textarea></td>
<td><textarea name="likes" rows="2" cols="30"></textarea></td>
<td><textarea name="dislikes" rows="2" cols="30"></textarea></td>
<td/><td><input type="submit" value="Add Crew"/></td></tr>
</table>
</form>

</body>
</html>